﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Engine;
using Game;
using Game.NetWork;
using Game.NetWork.Packages;
using Game.Server;
using Game.Server.Event;
using Game.Server.PlayerEvent;
using Game.Server.Plugins;
using GameEntitySystem;
using Newtonsoft.Json;
using static System.Net.Mime.MediaTypeNames;
using Engine.Graphics;
using System.Net.NetworkInformation;
using System.Media;
using TemplatesDatabase;
using Newtonsoft.Json.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
using System.Xml;
using OpenTK;
using LiteNetLib;
using System.Xml.Schema;
using OpenTK.Platform.MacOS;
using System.Linq;
using System.IO.Pipes;
using static Game.MotdManager;
using Vector3 = Engine.Vector3;


namespace Game.Server.Plugins
{
    public class GpsGet
    {
        public string Gps_Get(ComponentPlayer componentPlayer)
        {
            Vector3 position = componentPlayer.ComponentBody.Position;
            return "你的位置是 " + position.X.ToString("F1") + "," + position.Y.ToString("F1") + "," + position.Z.ToString("F1");
        }
    }
    public class SubsystemWeather1
    {
        public class CmdWeatherControl : AbstractProcessCmd
        {
            public override string Cmd => "gre"; // 指令名

            public override string Introduce => "/gre - 查看雨天控制器帮助"; // 指令说明

            public override int AuthLevel => 0; // 指令权限等级

            public override DisplayType Display => DisplayType.All; // 指令是否可查看

            public bool 下雨状态 = false;

            public Project Project = new Project();

            private void SendHelpMessage()
            {
                string text = "\n/gre off或on";
                base.SendMessage("查看距离控制命令=====>>>", text);
            }

            public void SendMsgPack(ComponentPlayer componentPlayer, string text)  //发送消息方法
            {
                MessagePackage messagePackage = new MessagePackage(null, text, 0, null);
                messagePackage.To = componentPlayer.PlayerData.Client;
                CommonLib.Net.QueuePackage(messagePackage);
            }

            public void Load()
            {

            }

            public override void ProcessCmd()//执行方法
            {
                string 玩家1 = null;
                string 玩家2 = null;
                bool flag = GameManager.Project == null;
                bool flag2 = flag;
                bool fr = false;
                if (flag2)
                {
                    base.SendMessage("距离查看操作器=====>>>", "你需要先开始游戏");
                }
                bool flag3 = false;
                SubsystemPlayers subsystemPlayers = GameManager.Project.FindSubsystem<SubsystemPlayers>();
                ComponentPlayer componentPlayer = this.m_client.PlayerData.ComponentPlayer;
                ComponentPlayer componentPlayer1 = this.m_client.PlayerData.ComponentPlayer;
                SubsystemExplosions subsystemExplosions = GameManager.Project.FindSubsystem<SubsystemExplosions>();

                int num = this.m_messageDatas.Length;//num 信息空格数长度 
                int num2 = num;
                int 距离d;
                if (num2 != 3)
                {
                    this.SendHelpMessage();
                }
                else
                {
                    foreach (PlayerData playersDatum in subsystemPlayers.PlayersData)
                        foreach (PlayerData playersDatum1 in subsystemPlayers.PlayersData)
                        {

                            bool flag7 = playersDatum.Name == this.m_messageDatas[1];
                            if (flag7)
                            {
                                玩家1 = this.m_messageDatas[1]; ;
                                bool flag8 = playersDatum.Name == this.m_messageDatas[2];
                                if (flag8)//执行
                                {
                                    玩家2 = this.m_messageDatas[2];

                                    componentPlayer1.PlayerData = playersDatum1;
                                    //计算玩家距离
                                    int num3 = 0;
                                    Vector3 position = componentPlayer.ComponentBody.Position;
                                    Vector3 position2 = componentPlayer1.ComponentBody.Position;
                                    SendMsgPack(componentPlayer, "你的位置是 " + position.X.ToString("F1") + "," + position.Y.ToString("F1") + "," + position.Z.ToString("F1"));
                                    SendMsgPack(componentPlayer1, "你的位置是 " + position2.X.ToString("F1") + "," + position2.Y.ToString("F1") + "," + position2.Z.ToString("F1"));                                   
                                    //Y是高度
                                    距离d = (int)Math.Sqrt(Math.Pow(position.X - position2.X, 2) + Math.Pow(position.Z - position2.Z, 2));
                                    SendMsgPack(componentPlayer, $"你与{componentPlayer1.PlayerData.Name}的距离是{距离d}");

                                }
                            }
                        }
                }

            }
        }
    }
}







/// <summary>
/// 指令执行
/// </summary>
